<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="top_header_left">
      </div>
      <div class="top_header_right">
        <el-button class="filter-item" type="primary" icon="el-icon-search" style="margin-left: 20px"
          @click="dialogFormVisible1 = true;">
          创建
        </el-button>
      </div>
    </div>

    <el-table ref="multipleTable" :data="list" stripe style="width: 1200px" border>
      <el-table-column prop="title" label="赛季名称" width="250" align="center" />
      <el-table-column prop="activity_name" label="赛季代码" width="200" align="center" />
      <el-table-column prop="total_money" label="赛事奖金" align="center" />
      <el-table-column prop="step_name" label="当前阶段" align="center" />
      <el-table-column fixed="right" label="操作" width="200" align="center">
        <template align="center" slot-scope="scope">
          <el-button type="button" size="small"
            @click="dialogFormVisible2 = true;time_list = scope.row;goodVoiceStepList()">
            设置阶段
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="创建" :visible.sync="dialogFormVisible1" style="width:1000px;margin:0 auto;" class="model_">
      <div class="center_lisr">
        <div>
          <span>赛事名称</span>
          <el-input v-model="add_match.title" placeholder="赛事名称" style="width:300px;max-width:70%;" />
        </div>
        <div>
          <span>赛季代码</span>
          <el-input v-model="add_match.activity_name" placeholder="赛季代码" style="width:300px;max-width:70%;" />
        </div>
        <div>
          <span>赛事奖励</span>
          <el-input v-model="add_match.total_money" placeholder="赛事奖励" style="width:300px;max-width:70%;" />
        </div>
        <div>
          <el-button class="filter-item" type="primary" style="width:100%;margin:0 auto;margin-top:10px"
            @click="voive_add">
            创建
          </el-button>
        </div>
      </div>

    </el-dialog>
    <el-dialog title="设置阶段" :visible.sync="dialogFormVisible2" style="width:1800px;margin:0 auto;" class="model_">
      <div class="center_lisr flex_de">
        <el-table ref="multipleTable" :data="stage_list" stripe style="width: 100%" border>
          <el-table-column prop="step" label="阶段" align="center" width="70">
            <template align="center" slot-scope="scope">
              <el-input v-model="scope.row.step" class="filteript" type="number"/>
            </template>
          </el-table-column>
          <el-table-column prop="step_name" label="阶段名称" align="center">
            <template align="center" slot-scope="scope">
              <el-input v-model="scope.row.step_name" class="filteript" />
            </template>
          </el-table-column>
          <el-table-column prop="step_subtitle" label="副标题" align="center">
            <template align="center" slot-scope="scope">
              <el-input v-model="scope.row.step_subtitle" class="filteript" />
            </template>
          </el-table-column>
          <el-table-column prop="start_time" label="开始时间" align="center" width="200">
            <template align="center" slot-scope="scope">
              <el-date-picker v-model="scope.row.start_time" type="date" placeholder="选择日期" format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss" prefix-icon=''/>
            </template>
          </el-table-column>
          <el-table-column prop="end_time" label="结束时间" align="center" width="200">
            <template align="center" slot-scope="scope">
              <el-date-picker v-model="scope.row.end_time" type="date" placeholder="选择日期" format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss" />
            </template>
          </el-table-column>
          <el-table-column fixed="right" prop="index" label="操作" align="center">
            <template align="center" slot-scope="scope">
              <el-button type="button" size="small" @click="voice_add(scope.row,scope.$index)">
                保存
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="new_row" @click="add_row">新增行</div>
      </div>
    </el-dialog>


  </div>
</template>
<script>
  import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
  import {
    encryption2
  } from "@/api/index";
  export default {
    name: "ComplexTable",
    components: {
      Pagination,
    },
    data() {
      return {
        add_match: {
          activity_name: '',
          title: '',
          total_money: '',
        },
        goodList: {}, //编辑列表
        nth: 1, //1上传歌手信息2评分
        dialogFormVisible1: false,
        dialogFormVisible2: false,
        formLabelWidth: '100px',
        userId: '',
        list: [],
        stage_list: [], //阶段列表
        time_list: {}, //点设置阶段
        add_obj: {}, //添加阶段
      };
    },
    created() {
      this.handleFilter();
    },

    methods: {
      // 创建
      voive_add() {
        const arys = {
          activity_name: this.add_match.activity_name,
          title: this.add_match.title,
          total_money: this.add_match.total_money,
        };
        const url = "/activity/goodVoiceAdd";
        encryption2(arys, url).then((res) => {
          if (res.data.status === 0) {
            this.handleFilter();
            this.add_match = {};
            this.dialogFormVisible1 = false;

            this.$message({
              message: res.data.text,
              type: "success",
            });
          } else {
            this.$message({
              message: res.data.text,
              type: "error",
            });
          }
        });
      },
      //保存
      voice_add(row,index) {
        console.log(index);
        if (row.id) {
          this.edit_step(row)
        } else {
          this.add_step(row,index)
        }
      },
      // 编辑
      edit_step(row) {
        const arys = {
          id: row.id,
          step: row.step,
          step_name: row.step_name,
          subtitle: row.step_subtitle,
          start_time: row.start_time,
          end_time: row.end_time,
        };
        const url = "/activity/goodVoiceStepEdit";
        encryption2(arys, url).then((res) => {
          if (res.data.status === 0) {
            this.$message({
              message: res.data.text,
              type: "success",
            });
          } else {
            this.$message({
              message: res.data.text,
              type: "error",
            });
          }
        });
      },
      //新增
      add_step(row,index) {
        const arys = {
          activity_name: row.activity_name,
          step: row.step,
          step_name: row.step_name,
          subtitle: row.step_subtitle,
          start_time: row.start_time,
          end_time: row.end_time,
        };
        const url = "/activity/goodVoiceStepAdd";
        encryption2(arys, url).then((res) => {
          if (res.data.status === 0) {
            this.stage_list[index].id = res.data.result.id;
            this.$message({
              message: res.data.text,
              type: "success",
            });
          } else {
            this.$message({
              message: res.data.text,
              type: "error",
            });
          }
        });
      },
      add_row() {
        let add = {
          activity_name: this.time_list.activity_name, //good_voice_2023
          step: '', //当前阶段
          step_name: '', //海选赛
          subtitle: '', //n进100
          start_time: '',
          end_time: '',
        }
        this.add_obj = add;
        this.stage_list.push(this.add_obj)
      },
      // 设置阶段
      goodVoiceStepList() {
        const arys = {
          activity_name: this.time_list
        };
        const url = "/activity/goodVoiceStepList";
        encryption2(arys, url).then((res) => {
          if (res.data.status === 0) {
            this.stage_list = res.data.result.list;
          } else {
            this.$message({
              message: res.data.text,
              type: "error",
            });
          }
        });
      },
      // 查询
      handleFilter() {
        const arys = {};
        const url = "/activity/goodVoiceList";
        encryption2(arys, url).then((res) => {
          if (res.data.status === 0) {
            this.list = res.data.result.list;
          } else {
            this.$message({
              message: res.data.text,
              type: "error",
            });
          }
        });
      },
    },
  };
</script>
<style scoped>
  .filter-container .filter-item {
    margin-bottom: 0;
  }

  .el-table--border {
    border-right: 1px solid #dfe6ec;
  }

  .el-alert {
    width: 1200px;
  }

  .filter-container {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 1200px;
  }

  .batch {
    width: 1200px;
    margin: 10px 0;
    display: flex;
    flex-direction: row-reverse;
  }

  .batch .filter-item {
    margin-left: 20px;
  }

  .el-dialog {
    width: 300px;
    height: 300px;
  }

  .center_lisr {
    width: 96%;
    height: 80%;
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;


  }

  .flex_de>div {
    display: flex;
    flex-direction: column;
  }

  .center_lisr>div {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
  }

  .center_lisr>div>el-input {
    flex: 1;
    margin-left: 20px;
  }

  .model_ /deep/ .el-dialog__body {
    padding-top: 0%;
  }

  .model_ /deep/ .el-button--mini {
    padding: 10px 20px;
  }

  .model_ /deep/ .el-dialog {
    border-radius: 4px;
  }

  .model_ /deep/ .el-input__inner {
    text-align: center;
  }

  .flex_de /deep/ .el-input__inner {
    padding: 0 4px;
    border: 0;
    background: 00000000;
  }

  .new_row {
    width: 80%;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #333;
    font-weight: blod;
    font-family: serif;
    cursor: pointer;
  }
</style>